package demo;

public class Test {

    public static void main(String[] args) {

        Animal animal = new Bird("小鸟",5);
        Bird bird = (Bird)animal;
        bird.fly();
        System.out.println("========");
        /*Animal animal1 = new Dog("旺财",9);
        Bird bird1 = (Bird)animal1;
        animal1.fly();*/
        if(animal instanceof Bird){
            Bird bird1 = (Bird)animal;
        }

    }



    public static void function(Animal animal){
        animal.eat();
    }
    public static void main2(String[] args) {
        Dog dog = new Dog("旺财",9);
        function(dog);
        System.out.println("=========");
        Bird bird = new Bird("小鸟",9);
        function(bird);
    }

    //向上转型
    //3.方法返回值
    public static Animal func1(Dog dog){
        return dog;
    }
    public static void func(Animal animal){

    }
    public static void main1(String[] args) {
        //1.直接
        Dog dog = new Dog("旺财",5);
        Animal animal = dog;
        //animal.bark();不能调用子类方法
        //animal.eat();只能调用自己的方法

        Animal animal1 = new Dog("11",3);

        //2方法传参
        Dog dog1 = new Dog("55",6);
        func(dog1);


        animal.eat();//输出的却是子类的方法输出


    }
}
